/*
 * ${beanName}Controller.java created on ${config.createTime?string("yyyy-MM-dd")} by ${config.createUser}
 */

package ${config.pack}.web;

import java.util.HashMap;
import java.util.LinkedHashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eking.framework.base.BaseController;
import org.eking.framework.common.BusinessMap;
import org.eking.framework.web.system.interceptor.CsrfToken;
import org.eking.framework.web.system.interceptor.DoLog;
import org.eking.framework.common.Pager;
import ${config.pack}.entity.${beanName};
import ${config.pack}.entity.${beanShowVo};
import ${config.pack}.entity.${beanQueryVo};
import ${config.pack}.service.${beanName}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


/**
 * ${config.beanDescription}控制器
 * TODO javadoc for org.eking.${beanName}.web.${beanName}Controller
 * @Copyright: ${config.copyright}
 * @author:${config.createUser}
 * @since: ${config.createTime?string("yyyy-MM-dd HH:mm:ss")}
 */
@Controller
@RequestMapping("/${simpleBeanName}")
public class ${beanName}Controller extends BaseController {

	@Autowired
	private ${beanName}Service ${simpleBeanName}Service;
	
	/**
	 * @description: 去到${config.beanDescription}列表页面
	 * @creator: ${config.createUser}
	 * @createDate: ${config.createTime?string("yyyy-MM-dd")} 
	 * @modifier:
	 * @modifiedDate:
	 * @param request
	 * @param response
	 * @param ${simpleBeanName}
	 * @return
	 */
	@RequestMapping("/list")
	@DoLog(content = "查看${config.beanDescription}列表信息")
	public ModelAndView list(HttpServletRequest request, HttpServletResponse response,${beanName} ${simpleBeanName}) {
		HashMap<String, Object> modelMap = new LinkedHashMap<String, Object>();
		modelMap.put("${simpleBeanName}", ${simpleBeanName});
		return new ModelAndView("${simpleBeanName}/list").addAllObjects(modelMap);
	}

	/**
	 * @description: ${config.beanDescription}列表ajax分页
	 * @creator: ${config.createUser}
	 * @createDate: ${config.createTime?string("yyyy-MM-dd")} 
	 * @modifier:
	 * @modifiedDate:
	 * @param request
	 * @param response
	 * @param page 
	 * @param ${simpleBeanName} 
	 * @throws Exception
	 */
	@RequestMapping("/ajaxPage")
	@DoLog(content = "${config.beanDescription}列表ajax分页")
	public void ajaxPage(HttpServletRequest request, HttpServletResponse response, Pager<${beanShowVo}> pager,${beanQueryVo} ${simpleBeanName}) throws Exception {
		${simpleBeanName}Service.search(pager,${simpleBeanName});
		this.genPageJson(response, pager);
	}

	/**
	 * @description: 去到添加${config.beanDescription}页面
	 * @creator: ${config.createUser}
	 * @createDate: ${config.createTime?string("yyyy-MM-dd")} 
	 * @modifier:
	 * @modifiedDate:
	 * @param request
	 * @param response
	 * @param ${simpleBeanName}
	 * @return
	 */
	@RequestMapping("/toAdd")
	@DoLog(content = "去到添加${config.beanDescription}页面")
	public ModelAndView toAdd(HttpServletRequest request, HttpServletResponse response,${beanName} ${simpleBeanName}) {
		HashMap<String, Object> modelMap = new LinkedHashMap<String, Object>();
		modelMap.put("${simpleBeanName}", ${simpleBeanName});		
		return new ModelAndView("${simpleBeanName}/add").addAllObjects(modelMap);
	}

	/**
	 * 添加${config.beanDescription}
	 * @creator: ${config.createUser}
	 * @createDate: ${config.createTime?string("yyyy-MM-dd")} 
	 * @modifier:
	 * @modifiedDate:
	 * @param request
	 * @param response
	 * @param ${simpleBeanName}
	 * @throws Exception
	 */
	@RequestMapping("/add")
	@DoLog(content = "添加${config.beanDescription}")
	@CsrfToken
	public void add(HttpServletRequest request, HttpServletResponse response,${beanName} ${simpleBeanName}) throws Exception {
		BusinessMap bm = ${simpleBeanName}Service.create(${simpleBeanName});
		this.ajax(response, bm);
	}

	/**
	 * @description: 去到编辑${config.beanDescription}页面
	 * @creator: ${config.createUser}
	 * @createDate: ${config.createTime?string("yyyy-MM-dd")} 
	 * @modifier:
	 * @modifiedDate:
	 * @param request
	 * @param response
	 * @param ${beanId}
	 * @return
	 */
	@RequestMapping("/toEdit")
	@DoLog(content = "去到编辑${config.beanDescription}页面")
	public ModelAndView toEdit(HttpServletRequest request, HttpServletResponse response, String ${beanId}) {
		${beanName} result = ${simpleBeanName}Service.getById(${beanId});
		HashMap<String, Object> modelMap = new LinkedHashMap<String, Object>();
		modelMap.put("${simpleBeanName}", result);
		return new ModelAndView("${simpleBeanName}/edit").addAllObjects(modelMap);
	}

	/**
	 * 编辑${config.beanDescription}
	 * @creator: ${config.createUser}
	 * @createDate: ${config.createTime?string("yyyy-MM-dd")} 
	 * @modifier:
	 * @modifiedDate:
	 * @param request
	 * @param response
	 * @param ${simpleBeanName}
	 * @throws Exception
	 */
	@RequestMapping("/edit")
	@DoLog(content = "编辑${config.beanDescription}")
	@CsrfToken
	public void edit(HttpServletRequest request, HttpServletResponse response, ${beanName} ${simpleBeanName}) throws Exception {
		BusinessMap bm = ${simpleBeanName}Service.edit(${simpleBeanName});
		this.ajax(response, bm);
	}

	/**
	 * @description: 查看${config.beanDescription}信息
	 * @creator: ${config.createUser}
	 * @createDate: ${config.createTime?string("yyyy-MM-dd")} 
	 * @modifier:
	 * @modifiedDate:
	 * @param request
	 * @param response
	 * @param ${beanId}
	 * @return
	 */
	@RequestMapping("/view")
	@DoLog(content = "查看${config.beanDescription}信息")
	public ModelAndView view(HttpServletRequest request, HttpServletResponse response, String ${beanId}) {
		${beanName} result = ${simpleBeanName}Service.getById(${beanId});
		return new ModelAndView("${simpleBeanName}/view").addObject("${simpleBeanName}", result);
	}

	/**
	 * @description: 删除${config.beanDescription}信息
	 * @creator: ${config.createUser}
	 * @createDate: ${config.createTime?string("yyyy-MM-dd")} 
	 * @modifier:
	 * @modifiedDate:
	 * @param request
	 * @param response
	 * @param ${beanId}
	 * @throws Exception
	 */
	@RequestMapping("/delete")
	@DoLog(content = "删除${config.beanDescription}信息")
	@CsrfToken
	public void delete(HttpServletRequest request, HttpServletResponse response, String ${beanId}) throws Exception {
		BusinessMap bm = ${simpleBeanName}Service.delete(${beanId});
		this.ajax(response, bm);
	}

}
